package com.aaa.service.fpa.impl;

import com.aaa.dao.fpa.TFpaRecordMapper;
import com.aaa.entity.MyPage;
import com.aaa.entity.fpa.TFpaRecord;
import com.aaa.entity.fpa.TjMessage;
import com.aaa.entity.fpa.Ttongji;
import com.aaa.service.fpa.TFpaRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (TFpaRecord)表服务实现类
 *
 * @author 李江波
 * @since 2022-10-25 15:46:19
 */
@Service
public class TFpaRecordServiceImpl implements TFpaRecordService {
   @Autowired
   private TFpaRecordMapper tFpaRecordMapper;

    @Override
    public TFpaRecord checkrecord(TFpaRecord record) {
        TFpaRecord tFpaRecord = tFpaRecordMapper.selectOne(record);
        return tFpaRecord;
    }

    @Override
    public int insertRecord(TFpaRecord record) {
        record.setCreatetime(new Date());
        int i = tFpaRecordMapper.insert(record);
        System.out.println(record.getId());
        return record.getId();
    }

    @Override
    public List<Ttongji> getTjData() {

        return tFpaRecordMapper.getTjData();
    }

    @Override
    public PageInfo getTjData2(MyPage myPage, TjMessage tjMessage) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());

        return new PageInfo(tFpaRecordMapper.getTjData2(tjMessage));
    }

    @Override
    public PageInfo getAll(MyPage myPage, TFpaRecord record) {
        PageHelper.startPage(myPage.getPage(), myPage.getLimit());
        Example example = new Example(TFpaRecord.class);
        if(record.getUsername()!=null){
            example.createCriteria().andLike("username",record.getUsername());
        }
        example.setOrderByClause("createtime desc");

        List<TFpaRecord> select = tFpaRecordMapper.selectByExample(example);
        PageInfo pageInfo = new PageInfo(select);
        return pageInfo;
    }

    @Override
    public PageInfo getDetailMsg(MyPage myPage, Integer id) {
        PageHelper.startPage(myPage.getPage(), myPage.getLimit());
        List<Map<String,Object>> details = tFpaRecordMapper.getDetails(id);
        PageInfo pageInfo = new PageInfo(details);
        return pageInfo;
    }
}

